
/*
*Released on 28th June 2008.
*Any violations can be reported at paritosh@wikiocean.net
*What is treated as violations can be found at www.wikiocean.net/ppl1-voilations*
******************************************************************************
* The contents of this file are subject to POOL Public License 1.0 and later.
* POOL Public License is based on Affero GPL v3 and additional conditions.
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the Affero GPL v3 License at http://www.gnu.org/licenses/agpl.html
* You may obtain a copy of the POOL Public License 1.0 or later at www.wikiocean.net/license/ppl.html
* Software distributed under POOL Public License 1.0 is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Initial Developer of the Original Code is Paritosh Pungaliya (C) 2008. All Rights Reserved.
******************************************************************************
* Objective of the additional terms (license)
* 1) Is to extend the software freedom to freedom to work.
* 2) To ensure that knowledge is free from monopoly of agencies.
* 3) To avoid a situation where big corporate or investor can buy out free software groups and companies and then start milking the communities built around it.
* (this trend can be seen how the freedom is curtailed in companies that get Venture Capital funding.)
******************************************************************************
*/

package  event;

import java.util.Hashtable;
import java.util.LinkedList;

import logger.PoolLogger;

import property.Property;
import database.RecordSearch;
import dbmanager.Column;
import dbmanager.DBManager;
import dbmanager.GetIdName;

public class Reflectparent implements Event 
{
	GetIdName gid;
	String object;
	String Request="request";
	String id;
	String Refelect="reflect";
	PoolLogger pl;
	
	public Reflectparent() {
		// logger
		pl = (PoolLogger) PoolLogger.getLogger(this.getClass().getName());
	}

	String type;

	


	public boolean getResult() 
	{
		Hashtable<Object, Object> table = new Hashtable<Object, Object>();
		table.put("mid", object);
		table.put("pid", Request);
		table.put("td", "null");
		RecordSearch rs =new RecordSearch();
		rs.setConditionMap(table);
		String line[] = rs.getArrayFromResultSet();
		for(int i=0;i<line.length;i++)
		{
			String splitline[] = line[i].split("\t");
			String value = splitline[Column.pv_index-1];
			if(value.equals("0"))
				Request = splitline[Column.vt_index-1];
			else
				Request = gid.getItem(value);
		}	
		table.put("pid",Refelect);
		rs.setConditionMap(table);
		line = rs.getArrayFromResultSet();
		if(line.length>0)
		{
			Hashtable<Object, Object> query = new Hashtable<Object, Object>();
			utility.findParentObject parenobject = new utility.findParentObject();
			parenobject.setDatabaseObject();
			for(int i=0;i<line.length;i++)
			{
				String splitline[] = line[i].split("\t");
				LinkedList<Object> reportlist= parenobject.findParentObject(id, splitline[Column.pv_index-1]);
				for(int j=0;j<reportlist.size();j++)
				{
					Property property =new Property();
					property.setMid(reportlist.get(i).toString());
					property.setPid(splitline[Column.pv_index-1]);
					String reporton= property.getValue();
					String reportname = gid.getItem(reportlist.get(i).toString());
					query.put("masterobject", reportname);
					query.put("status","0");
					query.put("process", "mod");
					query.put("mastertype", type);
					query.put("product", "pool");
					DBManager.getInsert("eventprocess", query);
				}
			}
		}	
		return true;
	}

	public void initializationData() 
	{
		gid =new GetIdName();
		Request =gid.getId(Request);  
		Refelect = gid.getId(Refelect);
	}

	public void setObject(String Object) 
	{
		this.object = Object;
	}
	
	public void SetData(String Product,String type, String masterid,String userid,String Process,String datetime,String request) 
	{
		this.id = masterid;
		this.type = type;
	}
	
	public static void main(String[] args) 
	{
		Reflectparent rp =new Reflectparent();		
		//rp.SetData("property_details", "","7289" , "", "");
		rp.setObject("10813");
		rp.initializationData();
		rp.getResult();
	}


	public boolean afterAdd() 
	{
		return getResult();
	}

	
	public boolean afterDel() 
	{
		return getResult();
	}

	
	public boolean afterMod() 
	{
		return getResult();
	}

	
	public boolean afterView() 
	{
		return getResult();
	}
}
